<template>
    <div class="main-con autoDistribute">
        <!-- 搜索框 -->
        <div class="search-con">
            <div class="search-item">
                <div class="search-item-title">门店名称</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.storeName" placeholder="请输入门店名称" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title">骑手名称</div>
                <div class="search-item-input">
                    <el-input size="mini" v-model="formData.horseman" placeholder="请输入骑手名称" @change="handleSearch"></el-input>
                </div>
            </div>
            <div class="search-item">
                <div class="search-item-title"></div>
                <el-button size="mini" type="primary" icon="el-icon-search" @click="handleSearch">查询</el-button>
                <el-button size="mini" type="primary" icon="el-icon-delete" @click="handleClear">清空</el-button>
            </div>
        </div>

        <!-- 表格数据 -->
        <div class="table-con" v-loading="loading">
            <el-table :data="tableData" size="mini" :header-cell-style="{background:'#f8f8f8'}" style="width: 100%">
                <el-table-column type="index" label="序号" width="50" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="storeName" label="门店名称" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="horseman" label="用户名" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="telPhone" label="手机号" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
                <el-table-column prop="deliveryingQuantity" label="订单量" width="" align="center" :show-overflow-tooltip="true">
                </el-table-column>
            </el-table>
        </div>

        <!-- 表格分页 -->
        <div class="pagination-con">
            <m-pagination :currentPage="formData.pageNum" :pageSize="formData.pageSize" :total="total"
                @handleCurrentChange="handleCurrentChange" @handleSizeChange="handleSizeChange">
            </m-pagination>
        </div>
    </div>
</template>

<script>
import { queryAutoDistributeInfo } from "@/common/service/horsemanManagement/autoDistribute.js";
import mPagination from "@/components/m-pagination/m-pagination";
export default {
    name: "autoDistribute",
    data() {
        return {
            // 搜索条件
            formData: {
                storeName: "", //门店名称
                horseman: "", //骑手名称
                pageNum: 1,
                pageSize: 10
            },

            //表格数据
            tableData: [], //表格信息
            total: null, //表格总条数
            loading: false //表格加载动画
        };
    },
    created() {
        //初始化表格数据
        this._queryAutoDistributeInfo();
    },
    methods: {
        /*----------------------------查询操作----------------------------*/
        //查询地区门店表格数据
        _queryAutoDistributeInfo() {
            this.loading = true;
            queryAutoDistributeInfo(this.formData)
                .then(res => {
                    this.loading = false;
                    this.tableData = res.list;
                    this.total = res.totalCount;
                })
                .catch(err => {
                    this.loading = false;
                    this.$message.error(err.message);
                });
        },
        //页码切换
        handleCurrentChange(val) {
            this.formData.pageNum = val;
            this._queryAutoDistributeInfo();
        },
        //每页展示条数的切换
        handleSizeChange(val) {
            this.formData.pageSize = val;
            this._queryAutoDistributeInfo();
        },
        //点击查询
        handleSearch() {
            this.formData.pageNum = 1;
            this.formData.pageSize = 10;
            this._queryAutoDistributeInfo();
        },
        //点击清空
        handleClear() {
            this.formData = {
                storeName: "",
                horseman: "",
                pageNum: 1,
                pageSize: 10
            };
            this.$message({
                type: "success",
                message: "清空成功!"
            });
            this._queryAutoDistributeInfo();
        }
    },
    components: {
        "m-pagination": mPagination
    }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.table-con {
    margin-top: 10px;
}
</style>